{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Serverless 简介\n",
    "\n",
    "Serverless是一种构建和管理基于微服务架构的完整流程，允许你在服务部署级别而不是服务器部署级别来管理你的应用部署，你甚至可以管理某个具体功能或端口的部署，这就能让开发者快速迭代，更快速地开发软件。\n",
    "\n",
    "Serverless有以下几个特点：\n",
    "\n",
    "* Serverless意味无维护，Serverless不代表完全去除服务器，而是代表去除有关对服务器运行状态的关心和担心，它们是否在工作，应用是否跑起来正常运行等等。Serverless代表的是你不要关心运营维护问题。有了Serverless，可以几乎无需Devops了。\n",
    "* Serverless不代表某个具体技术，有些人会给他们的语言框架取名为Serverless，Serverless其实去除维护的担心，如果你了解某个具体服务器技术当然有帮助，但不是必须的。\n",
    "* Serverless中的服务或功能代表的只是微功能或微服务，Serverless是思维方式的转变，从过去：“构建一个框架运行在一台服务器上，对多个事件进行响应。”变为：“构建或使用一个微服务或微功能来响应一个事件。”，你可以使用 django or node.js 和express等实现，但是serverless本身超越这些框架概念。框架变得也不那么重要了。\n",
    "\n",
    "## 腾讯云 Serverless\n",
    "\n",
    "腾讯云的Serverless产品，教程丰富，使用简洁，上手容易，可实现一条命令部署资源，值得学习。\n",
    "\n",
    "## Serverless Framework\n",
    "\n",
    "Serverless Framework 是业界非常受欢迎的无服务器应用框架，开发者无需关心底层资源即可部署完整可用的 Serverless 应用架构。Serverless Framework 具有资源编排、自动伸缩、事件驱动等能力，覆盖编码、调试、测试、部署等全生命周期，帮助开发者通过联动云资源，迅速构建 Serverless 应用。开发者部署应用时，Serverless Framework 会根据应用特性，自动完成云函数、API 网关、COS 等基础资源的部署和配置。开发者无需再手动部署配置每一项基础资源。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用Serverless Framework 部署静态网站\n",
    "\n",
    "通过该案例，可了解 Serverless 的优势。步骤如下：\n",
    "\n",
    "1. 安装 Serverless\n",
    "\n",
    "```bash\n",
    "npm install -g serverless\n",
    "```\n",
    "\n",
    "2. 创建网站项目。例如`myWebsite`中，将HTML、CSS、JS等内容放在某个文件夹中，例如`code`中。\n",
    "3. 创建`serverless.yml`配置文件，通过配置文件，设定访问路径，自定义域名，SSL证书等内容：\n",
    "\n",
    "```yml\n",
    "myWebsite:\n",
    "    component: \"@serverless/tencent-website\"\n",
    "    inputs:\n",
    "      code:\n",
    "        src: ./public\n",
    "        index: index.html\n",
    "        error: index.html\n",
    "      region: ap-guangzhou\n",
    "      bucketName: my-bucket\n",
    "      protocol: https\n",
    "      hosts:\n",
    "        - host: learningmakesmehappy.com\n",
    "          https:\n",
    "            certId: cp3pSwqr\n",
    "            http2: off\n",
    "            httpsType: 4\n",
    "            forceSwitch: -2\n",
    "```\n",
    "4. 部署。`sls --debug`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 参考资料\n",
    "\n",
    "1. <https://cloud.tencent.com/product/sls/details>\n",
    "1. <https://github.com/serverless-components/tencent-website>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
